package com.isnotlocus.gulimail.ware.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isnotlocus.common.utils.PageUtils;
import com.isnotlocus.common.utils.Query;

import com.isnotlocus.gulimail.ware.dao.PurchaseDetailDao;
import com.isnotlocus.gulimail.ware.entity.PurchaseDetailEntity;
import com.isnotlocus.gulimail.ware.service.PurchaseDetailService;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PurchaseDetailEntity> wrapper = new QueryWrapper<PurchaseDetailEntity>();
        if(params.get("key")!=null && !params.get("key").toString().equalsIgnoreCase("")){
            String key=params.get("key").toString();
            wrapper.and((item)->{
               item.eq("purchase_id",key).or().eq("sku_id",key);
            });
        }
        if(params.get("status")!=null &&!params.get("status").toString().equalsIgnoreCase("")){
            String status=params.get("status").toString();
            wrapper.eq("status",status);
        }

        if(params.get("wareId")!=null &&!params.get("wareId").toString().equalsIgnoreCase("")){
            String wareId=params.get("wareId").toString();
            wrapper.eq("ware_id",wareId);
        }
        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
               wrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<PurchaseDetailEntity> ListDetailPurchase(Long id) {
        List<PurchaseDetailEntity> list =this.list(new QueryWrapper<PurchaseDetailEntity>().eq("purchase_id",id));
        return list;
    }

}